package com.xxx;

import java.util.ArrayList;
import java.util.Scanner;

public class Test {

    static ArrayList<Account> acc = new ArrayList<>();
    static Scanner sc = new Scanner(System.in);
    static Account a = new Account();//当前操作对象


    public static void main(String[] args) {
        acc.add(new Account("6228147258", "666666", 0));

        System.out.println("---------欢迎使用中国银行ATM机---------");
        while (true) {
            System.out.println("请输入银行卡号：");
            if(okBankCard(sc.next())){
                break;
            }
        }
        Runnable deposit = new Deposit(a);
        Thread de = new Thread(deposit);
        Runnable withdrawer = new Withdrawer(a);
        Thread wd = new Thread(withdrawer);
        System.out.println("请输入密码：");
        for (int i = 3; i >= 1; i--) {
            if (sc.next().equals(a.getPassword())) {
                break;
            } else {
                System.out.println("密码错误，还剩" + i + "次机会！请重新输入密码");
            }
        }
        while (true) {
            System.out.println("请选择功能：1.取款 2.存款 3.查看余额 4.转账 5.退出");
            wd.start();
            de.start();
            switch (sc.next()){
                case "1":
                    //取钱
                    break;
                case "2":
                    ;//存钱
                    break;
                case "3":
                    System.out.println("您的余额为"+a.getMoney() + "元");
                    break;
                case "4":
                    break;
                case "5":
                    return;
                default:
                    System.out.println("没有该操作，重新输入！");
            }
        }
    }

    //判断银行卡号是否正确
    public static boolean okBankCard(String id){
        for (int i = 0; i < acc.size(); i++) {
            if (acc.get(i).getId().equals(id)){
                a = acc.get(i);
                return true;
            }
        }
        System.out.println("卡号错误，重新输入！");
        return false;

    }
}
